package com.pzhu.interceptors;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptors())
                .addPathPatterns("/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/index.html")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/fonts/**")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/api/user/login")
                .excludePathPatterns("/api/business/login")
                .excludePathPatterns("/api/user/register")
                .excludePathPatterns("/api/business/register")
                .excludePathPatterns("/api/hotel/u")
                .excludePathPatterns("/api/goods/u")
                .excludePathPatterns("/api/photograph/u")
                .excludePathPatterns("/api/createImage")
                .excludePathPatterns("/api/online/*");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
